package com.hd.trans.framework.dialog;

import com.chad.library.adapter.base.BaseNodeAdapter;
import com.chad.library.adapter.base.entity.node.BaseNode;
import com.hd.trans.common.Constants;
import com.hd.trans.db.bean.ChildBottomNode;
import com.hd.trans.db.bean.ChildTopNode;
import com.hd.trans.db.bean.FootNode;
import com.hd.trans.db.bean.HuDunLanguage;
import com.hd.trans.db.bean.LanguageGroup;
import com.hd.trans.framework.languages.ChildBottomProvider;
import com.hd.trans.framework.languages.ChildTopProvider;
import com.hd.trans.framework.languages.LanguageChildProvider;
import com.hd.trans.framework.languages.LanguageGroupProvider;
import com.hd.trans.framework.languages.RootFooterNodeProvider;

import java.util.List;

public class LanguageDialogAdapter extends BaseNodeAdapter {

    private HuDunLanguage checkedItem;


    public void setCheckedItem(HuDunLanguage item) {
        if (checkedItem != item) {
            checkedItem = item;
            //notifyDataSetChanged();
        }
    }

    public HuDunLanguage getCheckedItem() {
        return checkedItem;
    }


    public LanguageDialogAdapter() {
        super();
        // 注册Provider，总共有如下三种方式
        // 需要占满一行的，使用此方法（例如section）
        addFullSpanNodeProvider(new LanguageGroupProvider());
        // 普通的item provider
        addNodeProvider(new LanguageChildProvider());
        // 脚布局的 provider
        addFooterNodeProvider(new RootFooterNodeProvider());
    }

    public LanguageDialogAdapter(DialogType dialogType) {
        super();
        // 需要占满一行的，使用此方法（例如section）
        addFullSpanNodeProvider(new LanguageGroupProvider());
        // 普通的item provider
        addNodeProvider(new ChildTopProvider());
        addNodeProvider(new ChildBottomProvider());
        addNodeProvider(new LanguageChildProvider(dialogType));
        // 脚布局的 provider
        addFooterNodeProvider(new RootFooterNodeProvider());
    }

    @Override
    protected int getItemType(List<? extends BaseNode> list, int position) {
        BaseNode node = list.get(position);
        if (node instanceof LanguageGroup) {
            return Constants.LevelType.GROUP;
        } else if (node instanceof HuDunLanguage) {
            return Constants.LevelType.CHILD;
        } else if (node instanceof ChildTopNode) {
            return Constants.LevelType.CHILD_TOP;
        }else if (node instanceof ChildBottomNode) {
            return Constants.LevelType.CHILD_BOTTOM;
        }else if (node instanceof FootNode) {
            return Constants.LevelType.FOOT;
        }
        return -1;
    }
}
